<template>
  <!-- 注册 -->
  <div class="registerSubmit">
    <returnPage></returnPage>
    <van-form @submit="onRegister">
      <van-field
        v-model="code"
        name="code"
        label="验证码"
        placeholder="请输验证码"
        :rules="[{message: '请输验证码'}]"
      />
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="请输入用户名"
        :rules="[{message: '请输入用户名'}]"
      />
      <van-field
        v-model="password"
        name="password"
        label="请输入密码"
        placeholder="请输入密码"
        :rules="[{message: '请输入密码'}]"
      />
      <van-field
        v-model="repeatPassword"
        type="repeatPassword"
        name="repeatPassword"
        label="请确认密码"
        placeholder="请确认密码"
        :rules="[{message: '请确认密码'}]"
      />
      <div style="margin: 30px" class="button">
        <van-button
          round
          block
          type="info"
          native-type="submit"
          submit-on-enter="true"
          >确定</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from 'vant'
import request from '../../utils/request'
export default {
  name: 'registerSubmit',
  components: {},
  data () {
    return {
      code: '',
      username: '',
      password: '',
      repeatPassword: ''
    }
  },
  // 计算属性
  computed: {},
  watch: {},
  mounted () {},
  methods: {
    onRegister () {
      request
        .post('auth/register', {
          code: this.code,
          mobile: this.$route.params.id,
          username: this.username,
          password: this.password,
          repeatPassword: this.repeatPassword
        })
        .then((res) => {
          console.log(res)
          if (res.data.errmsg === '手机号已注册') {
            Toast('手机号已注册')
          } else {
            this.$router.push('/login')
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.registerSubmit {
  .van-form {
    margin-top: 30px;
    .button {
      margin-bottom: 30px;
    }
  }
}
</style>
